/*
 * @Descripttion: 
 * @TapdLink: https://XXX
 * @DesignsLink: https://XXX
 * @RelatedPersons: XXX[市场]、XXX[产品]、XXX[前端]、XXX[后端]、XXX[设计]
 * @version: 1.0.0
 * @Author: Shentong
 * @LastEditors: Shentong
 * @Date: 2021-10-25 11:33:46
 */
import { COUPONID, DEL_COUPONID, ADDCOUPONLIST, CLEARCOUPONLIST, ADD_REDPACK_ID, DEL_REDPACK_ID } from '../constants/index'

interface IPayload {
  couponId: string;
}

interface IAction<T> {
  payload: T;
  type: string;
}

const INIT_COUPON_ID = {
  couponId: ''
}

export function curConponId (state = INIT_COUPON_ID, action: IAction<IPayload> ) {
  switch (action.type) {
    case COUPONID:
      return {
        ...state,
        ...action.payload
      }
     case DEL_COUPONID:
       return {
         couponId: ''
       }
     default:
       return state
  }
}

/**
 * @description 优惠券实体
 * @param minusAmount 优惠金额 
 * @param fullAmount 使用门槛(满多少减)
 * @param validTime 有效期至
 */

interface IlistPayload {
  fullAmount: number;
  isUse: number;
  minusAmount: number;
  shopImageUrl: string;
  shopName: string;
  userCouponSId: string;
  userCouponId: string;
  validTime: string;
}

const INIT_COUPON_LIST = []

export function curConponList (state = INIT_COUPON_LIST, action: IAction<IlistPayload> ) {
  switch (action.type) {
    case ADDCOUPONLIST:
      return [
        ...action.payload
      ]
     case CLEARCOUPONLIST:
       return []
     default:
       return state
  }
}

/**
 * @description 选中红包
 */

const INIT_REDPACK_ID = {
  redPackId: ''
}

 export function curRedPackId (state = INIT_REDPACK_ID, action: IAction<IPayload> ) {
  switch (action.type) {
    case ADD_REDPACK_ID:
      return {
        ...state,
        ...action.payload
      }
     case DEL_REDPACK_ID:
       return {
        redPackId: ''
       }
     default:
       return state
  }
}